﻿
Imports System.Data.Sqlserverce


Public Class frmMainTest


    Private Sub frmMainTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'declaratie
        Dim cnnConnectie As New SqlCeConnection
        Dim cnnCommand As New SqlCeCommand
        Dim strStatement As String
        Dim dtrReader As SqlCeDataReader

        'initiatie databank
        cnnConnectie.ConnectionString = My.Settings.CnnMainProductdetail

        'sql statement
        strStatement = "SELECT Productnr FROM Producten "
        'command methodes

        With cnnCommand
            .Connection = cnnConnectie
            .CommandText = strStatement
            .CommandType = CommandType.Text
        End With
        Try
            cnnConnectie.Open()
        Catch ex As Exception
            MessageBox.Show("Er kan geen connectie worden gemaakt", "Voorraadbeheer", MessageBoxButtons.OKCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
        End Try

        If cnnConnectie.State = ConnectionState.Open Then
            Try
                dtrReader = cnnCommand.ExecuteReader()

                Do While dtrReader.Read
                    lsbProductnummer.Items.Add(dtrReader.Item(0))
                Loop

            Catch ex As Exception
                MessageBox.Show("Er is een fout opgetreden", "Voorraadbeheer", MessageBoxButtons.OKCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)

            Finally
                cnnConnectie.Close()
                dtrReader.Close()
            End Try
        End If
    End Sub

End Class
